package org.cug.uav.gcs.ui;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;

import com.sun.xml.internal.ws.Closeable;

public class FCParaSettingDlg extends Dialog {
	private DataBindingContext m_bindingContext;

	protected Object result;
	protected Shell shlFlightctrl;
	private Text text;
	private Group group;
	private Button btnCheckButton;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public FCParaSettingDlg(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shlFlightctrl.open();
		shlFlightctrl.layout();
		Display display = getParent().getDisplay();
		while (!shlFlightctrl.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shlFlightctrl = new Shell(getParent(), SWT.DIALOG_TRIM);
		shlFlightctrl.setSize(587, 499);
		shlFlightctrl.setText("Flight-Ctrl\u53C2\u6570\u8BBE\u7F6E");
		
		TabFolder FCParaSettingTab = new TabFolder(shlFlightctrl, SWT.BORDER);
		FCParaSettingTab.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				
			}
		});
		FCParaSettingTab.setSelection(1);
		FCParaSettingTab.setBounds(10, 10, 561, 364);
		
		TabItem channelsTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		channelsTabItem.setText("\u9065\u63A7\u5668\u901A\u9053");
		
		Composite channelTab = new Composite(FCParaSettingTab, SWT.NONE);
		channelsTabItem.setControl(channelTab);
		
		Label lblGas = new Label(channelTab, SWT.NONE);
		lblGas.setBounds(10, 10, 37, 12);
		lblGas.setText("GAS:");
		
		Combo gasCombo = new Combo(channelTab, SWT.NONE);
		gasCombo.setBounds(53, 10, 87, 20);
		
		TabItem configurationtabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		configurationtabItem.setText("\u9009\u9879");
		
		Composite configurationTab = new Composite(FCParaSettingTab, SWT.NONE);
		configurationtabItem.setControl(configurationTab);
		
		Label lblNameOf = new Label(configurationTab, SWT.NONE);
		lblNameOf.setBounds(10, 10, 64, 12);
		lblNameOf.setText("\u914D\u7F6E\u540D\u79F0:");
		
		text = new Text(configurationTab, SWT.BORDER);
		text.setBounds(80, 7, 70, 18);
		
		Group groupActive = new Group(configurationTab, SWT.NONE);
		groupActive.setText("\u63A7\u4EF6/\u529F\u80FD\u6FC0\u6D3B\u9009\u9879");
		groupActive.setBounds(10, 28, 529, 297);
		
		btnCheckButton = new Button(groupActive, SWT.CHECK);
		btnCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				m_bindingContext.updateTargets();
			}
		});
		btnCheckButton.setBounds(10, 25, 93, 16);
		btnCheckButton.setText("Altitude");
		
		TabItem stickTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		stickTabItem.setText("\u6447\u6746\u53C2\u6570");
		
		TabItem attitudeTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		attitudeTabItem.setText("\u9AD8\u5EA6\u63A7\u5236");
		
		Composite AltitudeTab = new Composite(FCParaSettingTab, SWT.NONE);
		attitudeTabItem.setControl(AltitudeTab);
		
		group = new Group(AltitudeTab, SWT.NONE);
		group.setBounds(10, 10, 339, 277);
		
		Combo combo_1 = new Combo(group, SWT.NONE);
		combo_1.setBounds(10, 10, 87, 20);
		
		TabItem cameraTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		cameraTabItem.setText("\u76F8\u673A");
		
		TabItem outputTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		outputTabItem.setText("\u8F93\u51FA");
		
		TabItem miscTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		miscTabItem.setText("\u6DF7\u63A7");
		
		TabItem naviTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		naviTabItem.setText("\u5BFC\u822A");
		
		TabItem gyroTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		gyroTabItem.setText("\u9640\u87BA\u4EEA");
		
		TabItem couplingTabItem = new TabItem(FCParaSettingTab, SWT.NONE);
		couplingTabItem.setText("\u8F74\u8026\u5408");
		
		Label label = new Label(shlFlightctrl, SWT.NONE);
		label.setBounds(10, 394, 72, 12);
		label.setText("\u5F53\u524D\u53C2\u6570\u96C6\uFF1A");
		
		Combo combo = new Combo(shlFlightctrl, SWT.NONE);
		combo.setItems(new String[] {"1", "2", "3", "4", "5"});
		combo.setBounds(88, 391, 87, 20);
		combo.select(1);
		combo.setText("1");
		
		Button btnNewButton = new Button(shlFlightctrl, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shlFlightctrl.close();
			}
		});
		btnNewButton.setBounds(10, 424, 72, 22);
		btnNewButton.setText("OK");
		
		Button btnRead = new Button(shlFlightctrl, SWT.NONE);
		btnRead.setBounds(225, 380, 72, 22);
		btnRead.setText("Read");
		
		Button btnWrite = new Button(shlFlightctrl, SWT.NONE);
		btnWrite.setBounds(335, 380, 72, 22);
		btnWrite.setText("Write");
		
		Button btnNewButton_1 = new Button(shlFlightctrl, SWT.NONE);
		btnNewButton_1.setBounds(225, 424, 72, 22);
		btnNewButton_1.setText("Load");
		
		Button btnNewButton_2 = new Button(shlFlightctrl, SWT.NONE);
		btnNewButton_2.setBounds(335, 424, 72, 22);
		btnNewButton_2.setText("Save");
		m_bindingContext = initDataBindings();

	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue groupObserveVisibleObserveWidget = SWTObservables.observeVisible(group);
		IObservableValue btnCheckButtonObserveSelectionObserveWidget = SWTObservables.observeSelection(btnCheckButton);
		bindingContext.bindValue(groupObserveVisibleObserveWidget, btnCheckButtonObserveSelectionObserveWidget, null, null);
		//
		return bindingContext;
	}
}
